// Anthropic API 接口定义
export interface AnthropicMessage {
  role: 'user' | 'assistant';
  content: string | AnthropicContentBlock[];
}

export interface AnthropicContentBlock {
  type: 'text' | 'image' | 'tool_use' | 'tool_result' | 'thinking';
  text?: string;
  source?: {
    type: 'base64';
    media_type: string;
    data: string;
  };
  name?: string;
  input?: any;
  tool_use_id?: string;
  content?: string;
  is_error?: boolean;
}

export interface AnthropicMessagesRequest {
  model: string;
  max_tokens: number;
  messages: AnthropicMessage[];
  system?: string | AnthropicContentBlock[];
  temperature?: number;
  top_k?: number;
  top_p?: number;
  stop_sequences?: string[];
  stream?: boolean;
  tools?: AnthropicTool[];
  tool_choice?: AnthropicToolChoice;
  thinking?: { enabled: boolean };
  container?: string;
  mcp_servers?: any[];
  metadata?: Record<string, any>;
  service_tier?: 'auto' | 'standard_only';
}

export interface AnthropicTool {
  name: string;
  description: string;
  input_schema: {
    type: 'object';
    properties: Record<string, any>;
    required?: string[];
  };
}

export interface AnthropicToolChoice {
  type: 'auto' | 'any' | 'tool' | 'none';
  name?: string;
}

export interface AnthropicMessagesResponse {
  id: string;
  type: 'message';
  role: 'assistant';
  content: AnthropicContentBlock[];
  model: string;
  stop_reason: 'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal';
  stop_sequence: string | null;
  usage: {
    input_tokens: number;
    output_tokens: number;
    cache_creation_input_tokens?: number;
    cache_read_input_tokens?: number;
  };
  container?: any;
}

export interface AnthropicCountTokensResponse {
  input_tokens: number;
}

export interface AnthropicModel {
  id: string;
  type: 'model';
  display_name: string;
  created_at: string;
}

export interface AnthropicModelsResponse {
  data: AnthropicModel[];
  first_id: string | null;
  last_id: string | null;
  has_more: boolean;
}

export interface AnthropicBatchRequest {
  custom_id: string;
  params: AnthropicMessagesRequest;
}

export interface AnthropicBatch {
  id: string;
  type: 'message_batch';
  processing_status: 'in_progress' | 'canceling' | 'ended';
  request_counts: {
    processing: number;
    succeeded: number;
    errored: number;
    canceled: number;
    expired: number;
  };
  created_at: string;
  expires_at: string;
  ended_at: string | null;
  results_url: string | null;
  metadata?: Record<string, any>;
}

export interface AnthropicBatchesRequest {
  requests: AnthropicBatchRequest[];
  metadata?: Record<string, any>;
}

export interface AnthropicFile {
  id: string;
  type: 'file';
  purpose: string;
  filename: string;
  size_bytes: number;
  created_at: string;
}

export interface AnthropicFilesResponse {
  data: AnthropicFile[];
  first_id: string | null;
  last_id: string | null;
  has_more: boolean;
}

export interface AnthropicErrorResponse {
  type: 'error';
  error: {
    type: 'invalid_request_error' | 'authentication_error' | 'permission_error' | 'not_found_error' | 'rate_limit_error' | 'api_error';
    message: string;
  };
}

// 请求日志接口
export interface AnthropicRequestLog {
  id: string;
  requestId?: string; // 用于链路追踪的统一请求ID
  timestamp: string;
  method: string;
  path: string;
  headers: Record<string, string>;
  body?: any;
  query?: Record<string, string>;
  ip: string;
  userAgent?: string;
  userId?: string;
  responseStatus?: number;
  responseTime?: number;
  apiKey?: string;
  
  // Extended query parameters
  beta?: boolean; // Beta features enabled
  
  // Extended headers for client context
  stainlessHeaders?: Record<string, string>; // X-Stainless-* headers
  anthropicBeta?: string; // anthropic-beta header value
  dangerousDirectBrowserAccess?: boolean; // anthropic-dangerous-direct-browser-access
  xApp?: string; // x-app header value
  
  // TODO: Add processing logic for these extended fields in logging
  // TODO: Add metrics collection based on client type (stainlessHeaders)
  // TODO: Add beta feature usage tracking
}